package com.jeesite.modules.task.oa.service;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.modules.task.oa.dto.JZResultDTO;
import com.jeesite.modules.task.oa.dto.OAUserOfficeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: xiaodong
 * @create: 2024-01-04
 * @Description:
 */
@Service("personSyncService")
@Slf4j
public class PersonSyncService {

    @Autowired
    private OAOfficeSyncService oaOfficeSyncService;

    public void execute(){
        log.info("person sync====start");
        String URL = "http://53.80.0.127:8080/baseUser/interface/getUserData?projectCode=DBJXT";
        String body = HttpRequest.post(URL).execute().body();
        JZResultDTO jzResultDTO = JSONObject.parseObject(body, JZResultDTO.class);
        log.info("人员库返回的信息："+ jzResultDTO.toString());
        if (jzResultDTO.isSuccess() && jzResultDTO.getData() != null){
            // 执行人员信息
            OAUserOfficeDTO oaUserOfficeDTO = JSONObject.parseObject(jzResultDTO.getData(), OAUserOfficeDTO.class);
            oaOfficeSyncService.syncUpdateUsers(oaUserOfficeDTO);
            log.info("数据同步完毕");
        }
        log.info("person sync====end");

    }
}
